﻿<Gui:XCaseGridBase
    x:Class="XCase.Gui.AssociationEndsGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Model="clr-namespace:XCase.Model;assembly=XCase.Model"
    xmlns:Gui="clr-namespace:XCase.Gui" >
    <StackPanel Name="stackPanel">
        <StackPanel.Resources>
            <Gui:ChangeLowerConverter x:Key="changeLowerConverter"/>
            <Gui:ChangeUpperConverter x:Key="changeUpperConverter"/>
            <Gui:ChangeRoleConverter x:Key="changeRoleConverter"/>
            <Gui:ToStringConverter x:Key="toStringConverter"/>
            <!-- Association end template -->
            <HierarchicalDataTemplate x:Key="associationEndTemplate" DataType="{x:Type Model:Association}" ItemsSource="{Binding Path=Ends}">
                <Grid Focusable="False" Margin="0,0,0,10" >
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Name="column1"  Width="60" MaxWidth="60"/>
                        <ColumnDefinition Name="column2"  MinWidth="62" />
                    </Grid.ColumnDefinitions>


                    <!-- Class -->
                    <TextBox Name="classLabel" Grid.Row="0" Grid.Column="0" IsReadOnly="True" Focusable="False"
                            >
                        Class
                    </TextBox>
                    <TextBox Name="classBox" Grid.Row="0" Grid.Column="1"  
                             Initialized="TextBox_Initialized"
                             KeyDown="KeyPressed_Down"
                             KeyUp="KeyPressed_Up"
                             IsVisibleChanged="TextBox_IsVisibleChanged"
                             Text="{Binding Path=Class,Converter={StaticResource toStringConverter}, Mode=OneWay}"
                             IsReadOnly="True"
                             />
                    <!-- Role -->
                    <TextBox Name="roleLabel" Grid.Row="1" Grid.Column="0" IsReadOnly="True" Focusable="False">
                        Role
                    </TextBox>
                    <TextBox Grid.Row="1" Grid.Column="1"  Name="roleBox"
                                  Text="{Binding Path=Name,Converter={StaticResource changeRoleConverter}}"  
                                  KeyDown="KeyPressed_Down"
                                  KeyUp="KeyPressed_Up"
                                  GotFocus="TextBox_GotFocus"
                                  IsVisibleChanged="TextBox_IsVisibleChanged"
                                  Initialized="TextBox_Initialized"
                            
                                  />
                    <!-- Lower -->
                    <TextBox Grid.Row="2" Grid.Column="0" IsReadOnly="True" Focusable="False">
                        Lower
                    </TextBox>
                    <TextBox Grid.Row="2" Grid.Column="1" Name="lowerBox"
                                  Text="{Binding Path=Lower, Converter={StaticResource changeLowerConverter}}"  
                                  KeyDown="KeyPressed_Down"
                                  KeyUp="KeyPressed_Up"
                                  IsVisibleChanged="TextBox_IsVisibleChanged"
                                  GotFocus="TextBox_GotFocus"
                                  Initialized="TextBox_Initialized"
                                  LostFocus="CheckCorrectMultiplicity" 
                                  />
                    <!-- Upper -->
                    <TextBox Grid.Row="3" Grid.Column="0" IsReadOnly="True" Focusable="False">
                        Upper
                    </TextBox>
                    <TextBox Grid.Row="3" Grid.Column="1" Name="upperBox"
                                  Text="{Binding Path=Upper, Converter={StaticResource changeUpperConverter}}"  
                                  KeyDown="KeyPressed_Down"
                                  KeyUp="KeyPressed_Up"
                                  Initialized="TextBox_Initialized"
                                  IsVisibleChanged="TextBox_IsVisibleChanged"
                                  GotFocus="TextBox_GotFocus"
                                  LostFocus="CheckCorrectMultiplicity" 
                                  />
                </Grid>
            </HierarchicalDataTemplate>
        </StackPanel.Resources>
        <Label Name="mainLabel" Focusable="True" Margin="5,3,3,5"> 
            Association Ends
        </Label>
        <ListView Name="endsBox" Focusable="False" Grid.Row="3" Grid.ColumnSpan="2" 
                      SelectionChanged="ListView_SelectionChanged"
                      ItemTemplate ="{StaticResource associationEndTemplate}"
                      HorizontalContentAlignment="Stretch"
                      BorderThickness="0"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                      ItemsSource="{Binding}"
                           Padding="0" Margin="2,0,0,0"          
                      KeyDown="KeyPressed_Down" Opacity="1" Background="Transparent">
            </ListView>
    </StackPanel>
</Gui:XCaseGridBase>